<!--
 * 首页
 -->
<template>
  <div class="home" id="home" name="home">
    <!-- 轮播图 -->
    <div class="block">
      <el-carousel :interval="4000" type="card" height="300px">
      <el-carousel-item v-for="item in this.carousels" :key="item.id">
        <img :src="item.picture" style="width: 100%; height: 300px" />
    </el-carousel-item>
  </el-carousel>
    </div>
    <!-- 轮播图END -->
    <div class="main-box">
      <div class="main">
        <!-- 热销商品展示区域 -->
        <div class="hot">
          <div class="box-hd">
            <div class="title">热销</div>
          </div>
          <div class="box-bd">
            <div class="promo-list">
              <router-link to>
                <img :src="$target +'public/imgs/hot/hot.png'" />
              </router-link>
            </div>
            <div class="list">
              <el-row :gutter="20">
                <el-col :span="6" v-for="item in hotList" :key="item.id">
                  <el-card 
                    :body-style="{ padding: '0px' }" 
                    class="hot-item"
                    @click.native="goToDetail(item.id)"
                  >
                    <img :src="item.picture" class="hot-image">
                    <div class="goods-info">
                      <h3 class="title">{{ item.title }}</h3>
                      <div class="price-info">
                        <span class="price">¥{{ item.price }}</span>
                        <span class="pay">{{ item.pay }}</span>
                      </div>
                      <div class="address">
                        <i class="el-icon-location"></i>
                        <span>{{ item.address }}</span>
                      </div>
                    </div>
                  </el-card>
                </el-col>
              </el-row>
            </div>
          </div>
        </div>
        <!-- 热销商品展示区域END -->
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      carousels: "", // 轮播图数据
      hotList: "", // 热销商品列表
      currentDate: new Date()
   
    };
  },
  created() {
    // 获取轮播图数据
    this.$axios
      .get("/products/app/carousel")
      .then(res => {
        this.carousels = res.data;
      })
      .catch(err => {
        return Promise.reject(err);
      });
    // 获取热门商品数据
    this.getHot();
  },
  methods: {
    // 获取热门商品数据方法
    getHot() {
     this.$axios
      .get("/products/app/hot")
      .then(res => {
        this.hotList = res.data;
      })
      .catch(err => {
        return Promise.reject(err);
      });
    },
    goToDetail(id) {
      this.$router.push(`/goods/detail/${id}`);
    }
  }
};
</script>
<style scoped>
@import "../assets/css/index.css";

.hot-item {
  cursor: pointer;
  margin-bottom: 20px;
  transition: all 0.3s;
}

.hot-item:hover {
  transform: translateY(-5px);
  box-shadow: 0 6px 12px rgba(0,0,0,0.1);
}

.hot-image {
  width: 100%;
  height: 200px;
  object-fit: cover;
  display: block;
}

.hot-info {
  padding: 14px;
}

.title {
  font-size: 14px;
  color: #333;
  margin: 0;
  height: 40px;
  line-height: 20px;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.price-info {
  margin: 10px 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.price {
  color: #ff6700;
  font-size: 18px;
  font-weight: bold;
}

.pay {
  color: #999;
  font-size: 12px;
}

.address {
  color: #666;
  font-size: 12px;
  margin-bottom: 10px;
}

.address i {
  margin-right: 5px;
}

.buy-btn {
  width: 100%;
  background-color: #ff6700;
  border-color: #ff6700;
}

.buy-btn:hover {
  background-color: #ff8500;
  border-color: #ff8500;
}

/* 确保一行显示4个商品 */
.el-col-6 {
  width: 25%;
}

/* 响应式布局 */
@media screen and (max-width: 1200px) {
  .el-col-6 {
    width: 33.33%;
  }
}

@media screen and (max-width: 768px) {
  .el-col-6 {
    width: 50%;
  }
}

@media screen and (max-width: 480px) {
  .el-col-6 {
    width: 100%;
  }
}
</style>